/**
 * 更新分享服务
 */
function updateSerivces() {
	plus.share.getServices(function(s) {
		shares = {};
		for(var i in s) {
			var t = s[i];
			shares[t.id] = t;
		}
		outSet("获取分享服务列表成功");
	}, function(e) {
		outSet("获取分享服务列表失败：" + e.message);
	});
}
/**
 * 分享操作
 */
function shareAction(id, ex,msg) {
	console.log('id = ' + id);
	console.log('ex = ' + ex);
	console.log('shares[id]' + shares[id]);
	var s = null;
	if(!id || !(s = shares[id])) {
		outLine("无效的分享服务！");
		return;
	}
	if(s.authenticated) {
		outSet("---已授权---");
		shareMessage(s, ex,msg);
	} else {
		outSet("---未授权---");
		s.authorize(function() {
			shareMessage(s, ex,msg);
		}, function(e) {
			outLine("认证授权失败");
		});
	}
}
/**
 * 发送分享消息
 */
function shareMessage(s, ex,msg) {
	var msg = {
		content: '分享-APP',
		href: 'http://www.huosgo.com/#/promote?recCode=tuhj24jem',
		title: '火速购分享',
		content: '火速购邀您使用',
		thumbs: ['https://www.pgyer.com/app/qrcode/IeNY'],
		pictures: ['https://www.pgyer.com/app/qrcode/IeNY'],
		extra: {
			scene: ex
		}
	};
	s.send(msg, function() {
		outLine("分享成功!");
	}, function(e) {
		outLine("分享失败!");
	});
}
/**
 * 分享按钮点击事件
 * 注意这里的这些id值
 */
function shareHref() {
	var ids = [{
			id: "weixin",
			ex: "WXSceneSession" /*微信好友*/
		}, {
			id: "weixin",
			ex: "WXSceneTimeline" /*微信朋友圈*/
		}, {
			id: "qq" /*QQ好友*/
		}, {
			id: "tencentweibo" /*腾讯微博*/
		}, {
			id: "sinaweibo" /*新浪微博*/
		}],
		bts = [{
			title: "发送给微信好友"
		}, {
			title: "分享到微信朋友圈"
		}, {
			title: "分享到QQ"
		}, {
			title: "分享到腾讯微博"
		}, {
			title: "分享到新浪微博"
		}];
	plus.nativeUI.actionSheet({
			cancel: "取消",
			buttons: bts
		},
		function(e) {
			var i = e.index;
			console.log('i = ' + i);
			if(i > 0) {
				shareAction(ids[i - 1].id, ids[i - 1].ex);
			}
		}
	);
}
// 控制台输出日志
function outSet(msg) {
	console.log(msg);
}
// 界面弹出吐司提示
function outLine(msg) {
	mui.toast(msg);
}
/**
 * 短信分享
 * **/
function shareBySMS(num) {
	console.log("电话号" + num);
	var msg = plus.messaging.createMessage(plus.messaging.TYPE_SMS);
	msg.to = [num];
	msg.body = '中意财险mass下载地址：https://www.pgyer.com/IeNY';
	plus.messaging.sendMessage(msg);
}
/**
 * 邮件分享
 * **/
function shareByEmail(num) {
	var msg = plus.messaging.createMessage(plus.messaging.TYPE_EMAIL);
	msg.to = [num];
	msg.body = '中意财险mass下载地址：https://www.pgyer.com/IeNY';
	plus.messaging.sendMessage(msg);
}
 
// 截屏绘制
var bitmap=null;
function screenshot(ws) {
	console.log(ws);
	bitmap = new plus.nativeObj.Bitmap("test");
	// 将webview内容绘制到Bitmap对象中
	console.log(bitmap)
	ws.draw(bitmap,function(){
		console.log('截屏绘制图片成功');
		bitmap.save('_www/img1.jpg', {
            overwrite: true
        },function(){
        	plus.io.resolveLocalFileSystemURL('_www/img1.jpg',function(entry){
        		entry.file(
        			function(file) {
                    canvasResize(file, {
                        width: 1000,
                        height: 1000,
                        crop: false,
                        quality: 50,
                        //压缩质量
                        rotate: 0,
                        format: 'jpg',
                        callback: function(data, width, height) {
                            f1 = data;
                        }
                    });
               });
        	},function(){});
        },function(){
        	console.log('save error')
        })
	},function(e){
		console.log('截屏绘制图片失败：'+JSON.stringify(e));
	});
	var sd_path = plus.io.convertLocalFileSystemURL('_www/img1.jpg');
	return sd_path;
//	plus.gallery.save('_www/img1.jpg',function(){
//		console.log('相册成功')
//	},function(){
//		console.log('相册失败')
//	})
}
